package com.stox.repository.object;

import java.io.File;
import java.io.IOException;

import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.stox.util.PathUtil;

public abstract class AbstractObjectRepository {

	protected static ObjectContainer database;
	
	static{
		File file = new File(PathUtil.getRootPath()+"database"+File.separator+"db.db4o");
		if(!file.exists()){
			file.getParentFile().mkdirs();
			try {
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		database = Db4oEmbedded.openFile(file.getAbsolutePath());
		Runtime.getRuntime().addShutdownHook(new Thread(){
			@Override
			public void run() {
				database.close();
			}
		});
	}
	
}
